﻿using Home.WebUI.Areas.NewAdmin.Models;
using System;
using System.Web.Mvc;
using Utilities;
using Utilities.ViewModel;
namespace Home.WebUI.Areas.Mythi.Controllers
{
    [Home.WebUI.Areas.NewAdmin.Models.AdminLogin]
    public class HomeController : Controller
    {
        //
        // GET: /NewAdmin/Home/
        //[AdminLogin]
        public ActionResult Index()
        {           
            ViewBag.OSFullName = Utilities.Environment.OSFullName;//操作系统
            ViewBag.NumberOfProcessors = Utilities.Environment.NumberOfProcessors;//处理器数量
            ViewBag.IIS = Request.ServerVariables["Server_SoftWare"].ToString();//iis
            ViewBag.IP = Request.ServerVariables["LOCAl_ADDR"].ToString();//ip
            ViewBag.ScriptTimeout = Server.ScriptTimeout.ToString() + "秒";//脚本超时时间
            ViewBag.DateTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);//系统时间
            ViewBag.EnglishName = System.Globalization.CultureInfo.InstalledUICulture.EnglishName;//系统语言
            ViewBag.TickCount = ((System.Environment.TickCount / 1000) / 60).ToString() + "分钟";//系统运行时间
            return View();
        }

        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(FormCollection form)
        {
            var adminName = Common.GetXmaData("AdminName");
            var passWord = Common.GetXmaData("AdminPassWord");
            if (adminName == Common.GetMD5(form["adminname"].Trim()) && passWord == Common.GetMD5(form["password"].Trim()))
            {
                Session["userprint"] = 1;
            }
            return RedirectToAction("index");
        }

        public ActionResult Bowout()
        {
            Session.Clear();
            return Redirect("/home/index");
        }

        public ActionResult EditPass()
        {
            return View();
        }
        [HttpPost]
        public ActionResult EditPass(FormCollection form)
        {
            var passWord = Common.GetXmaData("AdminPassWord");
            if (passWord == Common.GetMD5(form["password"].Trim()))
            {
                if (form["newpassword"].Trim()==form["vpassword"].Trim())
                {
                    Common.SetXmaData("AdminPassWord", Common.GetMD5(form["newpassword"].Trim()));
                    TempData["Tip"] = new TipModel(1, "修改成功");
                }
                else
                {
                    TempData["Tip"] = new TipModel(0, "重复密码错误");
                }
            }
            else
            {
                TempData["Tip"] = new TipModel(0, "原密码错误");
            }
            return View();
        }

    }
}
